# 元组的创建
tuple1 = (1, 2, 3, 4, 5, "hello", "你好", 1)
print(tuple1, type(tuple1))
list1 = [84, 34, 36, 92]
print(list1)
print(tuple(list1))
tuple2 = (1,)  # 元组只有一个元素时，加一个逗号
print(tuple2, type(tuple2))
# 转行成tuple类型
tuple3 = tuple("hello423你好")  # tuple(括号中只能是一个字符串,list)
print(tuple3, type(tuple3))
tuple4 = ()
print(tuple4)
print(type(tuple4))

# 类型转行
tuple5 = tuple("hello")  # str-->tuple
print(tuple5)
tuple6 = tuple([1, 2, 3, 4, 5, 6])  # list-->tuple
print(tuple6)
list1 = list(tuple6)  # tuple-->list
print(list1)
str1 = str(tuple5)  # tuple-->str
print(str1, type(str1))

# 序列的通用操作
print("*"*30)
# 索引
print(tuple1[-1])
# 切片
print(tuple1[::-2])
# len
print(len(tuple1))
# del
# del tuple1
# print(tuple1)  # name 'tuple1' is not defined. Did you mean: 'tuple2'?

# +
print(tuple1+tuple2)
# *
print(tuple2*3)
# in
print(1 in list1)

# 元组常用方法
a = tuple1.count(1)
print(a)
print(tuple1)
b = tuple1.index(1)  # .index返回的值是索引值
print(b)
# 元组的遍历
print("*"*30)
for i in tuple1:
    print(i, end=' ')
print()
for i in range(len(tuple1)):
    print(i, tuple1[i])
for index,value in enumerate(tuple1):
    print(index, value)